<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改个人信息</title>

    <%include ../../common.ejs%>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.zh-CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.form_datetime').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: "month",
                autoclose: true
            });
        })

        var checkTel = function () {
            if ($("#tel").val() == "") {
                $("#msg2").empty();
                return false;
            }
            var tel = $("#tel").val(); //获取手机号
            var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
            //如果手机号码不能通过验证
            if (telReg == false) {
                $("#msg2").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                return false;
            } else {
                var tag=true;
                $.ajax({
                    type:'post',
                    async:false,//同步提交
                    url: "/admin/peopleManagement/checkTel",
                    data: {
                        param: tel,
                        id: <%= user.id%>,
                    },
                    success: function (e) {
                        if (e.code == 200) {
                            $("#msg2").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                            tag=false;
                        }
                        else {
                            $("#msg2").html("<img src='/images/icons/success.png' style='height: 25px;width: 25px;'>");
                        }
                    }
                });
                if(tag==false){
                    return false;
                }
            }
        }

        var checkEmail=function(){
            if ($("#email").val() == "") {
                $("#msg3").empty();
                return false;
            }
            else {
                var email = $("#email").val();
                var tagEmail = !!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/);
                if (tagEmail == false) {
                    $("#msg3").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                    return false;
                } else {
                    $("#msg3").html("<img src='/images/icons/success.png' style='height: 25px;width: 25px;'>");
                }
            }
        }

        var checkAll = function () {
            if (checkTel() == false) {
                return false;
            }
            if (checkEmail()==false){
                return false;
            }
        }
        function submitForm() {
            if (checkAll() == false) {
                return false;
            }
        }
    </script>
    <style>
    </style>

</head>
<body>
<div id="top">
    <% include ../top.ejs%>
</div>
<div class="container-fluid" style="margin-top: 20px;">
    <div class="row">
        <div class="col-md-1">
        </div>
        <div id="left" class="col-md-2">
            <% include ../left.ejs%>
        </div>
        <div class="col-md-8 bodyDiv" id="right">
                    <div class="row">
                        <div class="col-md-12">
                            <form class="form-horizontal" role="form" method="post" action="updateUser"
                                  onsubmit="return checkAll()">

                                <span class="headTitle "><%= user.name %>的信息</span>

                                <div class="form-group">
                                    <br/><br/><label for="name" style="margin-left: 4cm"
                                                     class="col-sm-2 control-label">
                                        姓名：
                                    </label>

                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" id="name" name="name" value="<%= user.name %>"/>

                                    </div>
                                    性别：
                                    <INPUT type="radio" name="sex" checked value="M" <% if(user.sex=="M"){ %>checked<%}%>>男
                                    <INPUT type="radio" name="sex" value="F"<% if(user.sex=="F"){ %>checked<%}%>>女

                                </div>
                                <div class="form-group">
                                    <label for="birthday" style="margin-left: 4cm" class="col-sm-2 control-label">
                                        生日：
                                    </label>
                                    <div class="col-sm-4">
                                        <input size="16" type="text" id="birthday" name="birthday" readonly class="form-control form_datetime" value="<%= user.birthday %>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="tel" style="margin-left: 4cm" class="col-sm-2 control-label">
                                        手机号码：
                                    </label>

                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" id="tel" name="tel" value="<%= user.tel %>"
                                               onblur="checkTel()">
                                    </div>
                                    <div class="col-sm-1" id="msg2"></div>
                                </div>


                                <div class="form-group">
                                    <label for="email" style="margin-left: 4cm" class="col-sm-2 control-label">
                                        邮箱：
                                    </label>

                                    <div class="col-sm-4">
                                        <input type="email" class="form-control" id="email" onblur="checkEmail()" name="email" value="<%= user.email %>"/>
                                    </div>
                                    <div class="col-sm-1" id="msg3"></div>
                                </div>



                                <div class="form-group">
                                    <label for="address" style="margin-left: 4cm" class="col-sm-2 control-label">
                                        联系地址：
                                    </label>
                                    <div class="col-sm-7">
                                        <input type="text" class="form-control" id="address" name="address" value="<%= user.address %>"/>
                                    </div>
                                </div>


                                <div class="container-fluid">
                                    <div class="row">
                                        <div class="col-sm-offset-4 ">

                                            <br/>

                                            <button type="submit" style="width: 180px;" class="btn btn-default" onclick="submitForm()">
                                                修改
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            <input type="hidden" name="id" value="<%= user.id%>">
                            <input type="hidden" name="level" value="2">
                            </form>
                        </div>
                </div>
            <!--内容-->
        </div>
        <div class="col-md-1">
        </div>
    </div>

</div>
<br/>

</body>
</html>